package com.eclipse.org.snms.selializer.testCases;

import java.util.ArrayList;

import com.eclipse.org.snms.StickyNote;
import com.eclipse.org.snms.TaskComposite;
import com.eclipse.org.snms.serializer.stickyNoteList.StickyNoteList;
import com.eclipse.org.snms.serializer.updateStickyNote.ConcreteObserver;

import junit.framework.TestCase;
/**
 * 
 * @author jinzi
 *
 */
public class TestModify extends TestCase {
	StickyNoteList uniquaInstance = StickyNoteList.getUniqueInstance();
	ArrayList <StickyNote> stickyNoteList;
	
	public void testAdd(){
		//set one task in sticky note list
		TaskComposite task = new TaskComposite();
		int id = 101;
		String title = "old task";
		task.setId(id);
		task.setTitle(title);
		uniquaInstance.addStickyNote(task);			
		//add new task 
		TaskComposite newTask = new TaskComposite();
		int newId = 102;
		String newTitle = "new task";
		newTask.setId(newId);
		newTask.setTitle(newTitle);		
		ConcreteObserver co = new ConcreteObserver();
		co.update(newTask, 0);		
		//test if there are two tasks in sticky note list
		assertEquals(uniquaInstance.getStickyNote().size(),2);
		//test if the new task has the right value
		TaskComposite test = (TaskComposite)uniquaInstance.getStickyNote().get(1);
		assertEquals(test.getId(), newId);
		assertEquals(test.getTitle(), newTitle);
		//clear 
		uniquaInstance.getStickyNote().clear();		
	}

	public void testDelete(){
		//set one task in sticky note list
		TaskComposite task1 = new TaskComposite();
		int id = 101;
		String title = "first task";
		task1.setId(id);
		task1.setTitle(title);
		uniquaInstance.addStickyNote(task1);		
		//set second task in sticky note list
		TaskComposite task2 = new TaskComposite();
		int newId = 102;
		String newTitle = "second task";
		task2.setId(newId);
		task2.setTitle(newTitle);		
		uniquaInstance.addStickyNote(task2);
		//test the size before removing any task
		assertEquals(uniquaInstance.getStickyNote().size(), 2);
		//remove first task
		ConcreteObserver co = new ConcreteObserver();
		co.update(task1, 2);
		//test if there are one task in sticky note list after deleting the first task
		assertEquals(uniquaInstance.getStickyNote().size(), 1);
		//test if the remaining task has the right value
		TaskComposite test = (TaskComposite)uniquaInstance.getStickyNote().get(0);
		assertEquals(test.getId(), newId);
		assertEquals(test.getTitle(), newTitle);	
		//clear 
		uniquaInstance.getStickyNote().clear(); 		
	}
	
	public void testUpdate(){
		//set one task in sticky note list
		TaskComposite task1 = new TaskComposite();
		int id = 101;
		String title = "first task";
		task1.setId(id);
		task1.setTitle(title);
		uniquaInstance.addStickyNote(task1);		
		//set second task in sticky note list
		TaskComposite task2 = new TaskComposite();
		int secondId = 102;
		String secondTitle = "second task";
		task2.setId(secondId);
		task2.setTitle(secondTitle);		
		uniquaInstance.addStickyNote(task2);
		//test the size before removing any task
		assertEquals(uniquaInstance.getStickyNote().size(), 2);
		//update first task
		ConcreteObserver co = new ConcreteObserver();
		TaskComposite task3 = new TaskComposite();
		String newTitle = "Updated Task";
		task3.setId(id);
		task3.setTitle(newTitle);
		co.update(task3, 1);
		//test if there are two task in sticky note list after updating the first task
		assertEquals(uniquaInstance.getStickyNote().size(), 2);
		//test if the remaining task has the right value
		TaskComposite test = (TaskComposite)uniquaInstance.getStickyNote().get(0);
		assertEquals(test.getId(), id);
		assertEquals(test.getTitle(), newTitle);	
		//clear 
		uniquaInstance.getStickyNote().clear(); 		
	}
}
